package com.csk.zsk.compents.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.csk.zsk.commons.action.AjaxActionSupport;
import com.csk.zsk.commons.utils.encode.JsonBinder;
import com.csk.zsk.commons.utils.web.struts2.Struts2Utils;
import com.csk.zsk.compents.entity.WeatherCode;
import com.csk.zsk.compents.service.WeatherCodeService;
@Controller
@Scope("prototype")
public class WeatherCodeAction extends AjaxActionSupport {

	private static final long serialVersionUID = -9011877329197810252L;
	private static JsonBinder binder = JsonBinder.buildNonDefaultBinder();
	@Autowired
	private WeatherCodeService weatherCodeService;
	
	private String codeid;
	private String cityname;
	private String level;
	private String code;
	
	public String getCodeid() {
		return codeid;
	}
	public void setCodeid(String codeid) {
		this.codeid = codeid;
	}
	public String getCityname() {
		return cityname;
	}
	public void setCityname(String cityname) {
		this.cityname = cityname;
	}
	public String getLevel() {
		return level;
	}
	public void setLevel(String level) {
		this.level = level;
	}
	
	/**
	 * 通过id获取城市天气代码对象
	 */
	public void getWeatherCodeById(){
		if(codeid==null||codeid.equals("")){
			return;
		}
		WeatherCode wc = weatherCodeService.getWeatherCodeById(codeid);
		String json = binder.toJson(wc);
		Struts2Utils.renderJson(json);

	}
	/**
	 * 通过级别获得城市天气代码列表
	 */
	public void getWeatherCodeListByLevel(){
		if(level==null||level.equals("")){
			return;
		}
		List<WeatherCode> wclist = weatherCodeService.getWeatherCodeListByLevel(level);
		String json = binder.toJson(wclist);
		Struts2Utils.renderJson(json);
	}
	/**
	 * 通过代码获取子级别城市天气代码列表
	 */
	public void getSubWeatherCodeList(){
		if(code==null||code.equals("")){
			return;
		}
		List<WeatherCode> wclist = weatherCodeService.getSubWeatherCodeList(code);
		String json = binder.toJson(wclist);
		Struts2Utils.renderJson(json);
	}
	/**
	 * 通过城市名称和级别获取城市天气代码对象
	 */
	public void getWeatherCodeByName(){
		if(cityname==null||level==null||cityname.equals("")||level.equals("")){
			return;
		}
		WeatherCode wc = weatherCodeService.getWeatherCodeByName(cityname, level);
		String json = binder.toJson(wc);
		Struts2Utils.renderJson(json);
	}
	
	
	

}
